package com.nhim.cms.admin.server.locator;

import com.google.web.bindery.requestfactory.shared.Locator;
import com.nhim.cms.admin.shared.EElementType;
import com.nhim.cms.dao.ElementDefinitionDAO;
import com.nhim.cms.domain.ElementDefinition;
import com.nhim.core.AppContext;

public class ElementDefinitionLocator extends Locator<ElementDefinition, Integer> {
	
	ElementDefinitionDAO EDFDAO = ElementDefinitionDAO.getFromApplicationContext(AppContext.getApplicationContext());
	
	@Override
	public ElementDefinition create(Class<? extends ElementDefinition> clazz) {
		ElementDefinition newElement = new ElementDefinition();
		newElement.setName("");
		newElement.setAllowEdit(true);
		newElement.setDefaultValue("");
		newElement.setDefinitionText("");
		newElement.setDescription("");
		newElement.setElementType(EElementType.TEXTBOX.toString());
		newElement.setIsSearchable(true);
		newElement.setIsMetadata(false);
		newElement.setVersion(1);
		return new ElementDefinition();
	}

	@Override
	public ElementDefinition find(Class<? extends ElementDefinition> clazz,
			Integer id) {
		
		if (id == null)
			return new ElementDefinition();
		return EDFDAO.findById(id);
	}

	@Override
	public Class<ElementDefinition> getDomainType() {
		return ElementDefinition.class;
	}

	@Override
	public Integer getId(ElementDefinition domainObject) {
		return domainObject.getId();
	}

	@Override
	public Class<Integer> getIdType() {
		return Integer.class;
	}

	@Override
	public Object getVersion(ElementDefinition domainObject) {
		return domainObject.getVersion();
	}
	
	

}
